﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using DataAccess;
using System.Windows.Controls;
using SPIWareMVVM.Views.Commands;

namespace SPIWareMVVM.ViewModels
{
    public class WorkOrdersViewModel : BaseViewModel
    {
        Customer _selectedCustomer;
        public Customer SelectedCustomer
        {
            get
            {
                return _selectedCustomer;
            }
            set
            {
                _selectedCustomer = value;
                OnPropertyChanged("SelectedCustomer");
                OnPropertyChanged("SelectedWorkOrders");
            }
        }

        List<WorkOrder> _workOrders;
        public ObservableCollection<WorkOrder> SelectedWorkOrders
        {
            get
            {
                if (_workOrders == null) _workOrders = (from w in context.WorkOrders select w).ToList();
                ObservableCollection<WorkOrder> list = _workOrders.ToObservableCollection<WorkOrder>();
                if (ApplicationData.SelectedCustomer != null) list = list.GetByCustomer(ApplicationData.SelectedCustomer);
                return list;
            }
            set { }
        }

        private ViewAllPartsCommand _viewAllPartsCommand { get; set; }
        public ViewAllPartsCommand ViewAllPartsCommand
        {
            get
            {
                if (_viewAllPartsCommand == null) _viewAllPartsCommand = new ViewAllPartsCommand(this);
                return _viewAllPartsCommand;
            }
        }
    }
}
